//
//  Helper.m
//  LordApp
//
//  Created by a on 2018/8/27.
//  Copyright © 2018年 a. All rights reserved.
//

#import "Helper.h"

#import "sys/utsname.h"
#import <AdSupport/AdSupport.h>
#import <ifaddrs.h>
#import <arpa/inet.h>
#import <sys/sockio.h>
#import <sys/ioctl.h>
#include <sys/socket.h> // Per msqr
#include <sys/sysctl.h>
#include <net/if.h>
#include <net/if_dl.h>
#import <AVFoundation/AVFoundation.h>

#define IOS_CELLULAR @"pdp_ip0"
//有些分配的地址为en0 有些分配的en1
#define IOS_WIFI2 @"en2"
#define IOS_WIFI1 @"en1"
#define IOS_WIFI @"en0"
//#define IOS_VPN       @"utun0"  vpn很少用到可以注释
#define IP_ADDR_IPv4 @"ipv4"
#define IP_ADDR_IPv6 @"ipv6"

@implementation Helper

#pragma mark -  获取手机机型
/**
 *  获取手机机型
 *
 *  @return 手机机型
 */
+ (NSString*)iphoneType {
    
    struct utsname systemInfo;
    
    uname(&systemInfo);
    
    NSString*platform = [NSString stringWithCString: systemInfo.machine encoding:NSASCIIStringEncoding];
    
    if([platform isEqualToString:@"iPhone1,1"])  return@"iPhone 2G";
    
    if([platform isEqualToString:@"iPhone1,2"])  return@"iPhone 3G";
    
    if([platform isEqualToString:@"iPhone2,1"])  return@"iPhone 3GS";
    
    if([platform isEqualToString:@"iPhone3,1"])  return@"iPhone 4";
    
    if([platform isEqualToString:@"iPhone3,2"])  return@"iPhone 4";
    
    if([platform isEqualToString:@"iPhone3,3"])  return@"iPhone 4";
    
    if([platform isEqualToString:@"iPhone4,1"])  return@"iPhone 4S";
    
    if([platform isEqualToString:@"iPhone5,1"])  return@"iPhone 5";
    
    if([platform isEqualToString:@"iPhone5,2"])  return@"iPhone 5";
    
    if([platform isEqualToString:@"iPhone5,3"])  return@"iPhone 5c";
    
    if([platform isEqualToString:@"iPhone5,4"])  return@"iPhone 5c";
    
    if([platform isEqualToString:@"iPhone6,1"])  return@"iPhone 5s";
    
    if([platform isEqualToString:@"iPhone6,2"])  return@"iPhone 5s";
    
    if([platform isEqualToString:@"iPhone7,1"])  return@"iPhone 6 Plus";
    
    if([platform isEqualToString:@"iPhone7,2"])  return@"iPhone 6";
    
    if([platform isEqualToString:@"iPhone8,1"])  return@"iPhone 6s";
    
    if([platform isEqualToString:@"iPhone8,2"])  return@"iPhone 6s Plus";
    
    if([platform isEqualToString:@"iPhone8,3"])  return@"iPhone SE";
    
    if([platform isEqualToString:@"iPhone8,4"])  return@"iPhone SE";
    
    if([platform isEqualToString:@"iPhone9,1"])  return@"iPhone 7";
    
    if([platform isEqualToString:@"iPhone9,3"])  return@"iPhone 7";
    
    if([platform isEqualToString:@"iPhone9,2"])  return@"iPhone 7 Plus";
    
    if([platform isEqualToString:@"iPhone9,4"])  return@"iPhone 7 Plus";
    
    if([platform isEqualToString:@"iPhone10,1"]) return@"iPhone 8";
    
    if([platform isEqualToString:@"iPhone10,4"]) return@"iPhone 8";
    
    if([platform isEqualToString:@"iPhone10,2"]) return@"iPhone 8 Plus";
    
    if([platform isEqualToString:@"iPhone10,5"]) return@"iPhone 8 Plus";
    
    if([platform isEqualToString:@"iPhone10,3"]) return@"iPhone X";
    
    if([platform isEqualToString:@"iPhone10,6"]) return@"iPhone X";
    
    if([platform isEqualToString:@"iPhone11,2"]) return@"iPhone XS";
    
    if([platform isEqualToString:@"iPhone11,4"]) return@"iPhone XS Max";
    
    if([platform isEqualToString:@"iPhone11,6"]) return@"iPhone XS Max";
    
    if([platform isEqualToString:@"iPhone11,8"]) return@"iPhone XR";
    
    if([platform isEqualToString:@"iPhone12,1"]) return@"iPhone 11";
    
    if([platform isEqualToString:@"iPhone12,3"]) return@"iPhone 11 Pro Max";
    
    if([platform isEqualToString:@"iPhone12,5"]) return@"iPhone 11 Pro";
    
    if([platform isEqualToString:@"iPod1,1"])  return@"iPod Touch 1G";
    
    if([platform isEqualToString:@"iPod2,1"])  return@"iPod Touch 2G";
    
    if([platform isEqualToString:@"iPod3,1"])  return@"iPod Touch 3G";
    
    if([platform isEqualToString:@"iPod4,1"])  return@"iPod Touch 4G";
    
    if([platform isEqualToString:@"iPod5,1"])  return@"iPod Touch 5G";
    
    if([platform isEqualToString:@"iPad1,1"])  return@"iPad 1G";
    
    if([platform isEqualToString:@"iPad2,1"])  return@"iPad 2";
    
    if([platform isEqualToString:@"iPad2,2"])  return@"iPad 2";
    
    if([platform isEqualToString:@"iPad2,3"])  return@"iPad 2";
    
    if([platform isEqualToString:@"iPad2,4"])  return@"iPad 2";
    
    if([platform isEqualToString:@"iPad2,5"])  return@"iPad Mini 1G";
    
    if([platform isEqualToString:@"iPad2,6"])  return@"iPad Mini 1G";
    
    if([platform isEqualToString:@"iPad2,7"])  return@"iPad Mini 1G";
    
    if([platform isEqualToString:@"iPad3,1"])  return@"iPad 3";
    
    if([platform isEqualToString:@"iPad3,2"])  return@"iPad 3";
    
    if([platform isEqualToString:@"iPad3,3"])  return@"iPad 3";
    
    if([platform isEqualToString:@"iPad3,4"])  return@"iPad 4";
    
    if([platform isEqualToString:@"iPad3,5"])  return@"iPad 4";
    
    if([platform isEqualToString:@"iPad3,6"])  return@"iPad 4";
    
    if([platform isEqualToString:@"iPad4,1"])  return@"iPad Air";
    
    if([platform isEqualToString:@"iPad4,2"])  return@"iPad Air";
    
    if([platform isEqualToString:@"iPad4,3"])  return@"iPad Air";
    
    if([platform isEqualToString:@"iPad4,4"])  return@"iPad Mini 2G";
    
    if([platform isEqualToString:@"iPad4,5"])  return@"iPad Mini 2G";
    
    if([platform isEqualToString:@"iPad4,6"])  return@"iPad Mini 2G";
    
    if([platform isEqualToString:@"iPad4,7"])  return@"iPad Mini 3";
    
    if([platform isEqualToString:@"iPad4,8"])  return@"iPad Mini 3";
    
    if([platform isEqualToString:@"iPad4,9"])  return@"iPad Mini 3";
    
    if([platform isEqualToString:@"iPad5,1"])  return@"iPad Mini 4";
    
    if([platform isEqualToString:@"iPad5,2"])  return@"iPad Mini 4";
    
    if([platform isEqualToString:@"iPad5,3"])  return@"iPad Air 2";
    
    if([platform isEqualToString:@"iPad5,4"])  return@"iPad Air 2";
    
    if([platform isEqualToString:@"iPad6,3"])  return@"iPad Pro 9.7";
    
    if([platform isEqualToString:@"iPad6,4"])  return@"iPad Pro 9.7";
    
    if([platform isEqualToString:@"iPad6,7"])  return@"iPad Pro 12.9";
    
    if([platform isEqualToString:@"iPad6,8"])  return@"iPad Pro 12.9";
    
    if([platform isEqualToString:@"i386"])  return@"iPhone Simulator";
    
    if([platform isEqualToString:@"x86_64"])  return@"iPhone Simulator";
    
    return platform;
    
}

+ (BOOL)isiphoneSimulator {
    
    struct utsname systemInfo;
    
    uname(&systemInfo);
    
    NSString*platform = [NSString stringWithCString: systemInfo.machine encoding:NSASCIIStringEncoding];
    if([platform isEqualToString:@"i386"])  return  true;
    
    if([platform isEqualToString:@"x86_64"])  return true;
    
    return false;
}


#pragma mark - 字典转Json字符串
+ (NSString*)convertToJSONData:(id)infoDict
{
    
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:infoDict
                                                       options:0 // Pass 0 if you don't care about the readability of the generated string
                                                         error:&error];
    
    NSString *jsonString = @"";
    
    if (! jsonData)
    {
        NSLog(@"Got an error: %@", error);
    }else
    {
        jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    
    jsonString = [jsonString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];  //去除掉首尾的空白字符和换行字符
    
    [jsonString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    
    return jsonString;
}

#pragma mark - JSON字符串转化为字典
+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString
{
    if (jsonString == nil) {
        return nil;
    }
    
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:NSJSONReadingMutableContainers
                                                          error:&err];
    if(err)
    {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}


//根据宽度求高度  content 计算的内容  width 计算的宽度 font字体大小
+ (CGFloat)getLabelHeightWithText:(NSString *)text width:(CGFloat)width font: (CGFloat)font
{
    CGRect rect = [text boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:MY_SCALE_FONT(font)} context:nil];
    
    return rect.size.height;
}

//根据高度度求宽度  text 计算的内容  Height 计算的高度 font字体大小
+ (CGFloat)getWidthWithText:(NSString *)text height:(CGFloat)height font:(UIFont *)font {
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake(MAXFLOAT, height)
                                     options:NSStringDrawingUsesLineFragmentOrigin
                                  attributes:@{NSFontAttributeName:font}
                                     context:nil];
    return rect.size.width;
}

//获取当前的时间
+(NSString*)getCurrentTimes:(NSString *)format{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:format]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    //设置时区,这个对于时间的处理有时很重要
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    [formatter setTimeZone:timeZone];
    NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
    //      NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]*1000];
    //return timeSp;
    NSString *currentTimeString = [formatter stringFromDate:datenow];
    return currentTimeString;
    
}

+ (NSString *)getCurrentQUJIAN{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"HH"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    //设置时区,这个对于时间的处理有时很重要
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    [formatter setTimeZone:timeZone];
    NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
    //      NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]*1000];
    //return timeSp;
    NSString *currentTimeString = [formatter stringFromDate:datenow];
    int tempQujian = [currentTimeString intValue];
    if(tempQujian <= 3){
        return @"凌晨";
    }else if(tempQujian <= 11){
        return @"上午";
    }else if(tempQujian == 12){
        return @"中午";
    }else if(tempQujian <= 18){
        return @"下午";
    }else if(tempQujian <= 23){
        return @"晚上";
    }else if(tempQujian <= 24){
        return @"午夜";
    }
    return  @"未知";
}

/**
 返回默认头像占位图
 */
+ (UIImage *)returnAvaterImage {
    return [UIImage imageNamed:@"common_avatar_bg"];
}

+ (UIImage *)returnProductImage {
    return [UIImage imageNamed:@"common_goods_bg"];
}

+(UIImage *)returnDynamicListImage {
    return [UIImage imageNamed:@"common_dynamic_list_bg"];
}
/**
 返回默认图片占位图
 */
+ (UIImage *)returnDownLoadImage {
    return [UIImage imageNamed:@"img_zhanweibg"];
}


+(void)createAlertWithTitle:(NSString *)title andLeftBtnClick:(void (^)(void))leftBlock andLeftTitle:(NSString *)leftTitle andRightBtnClick:(void (^)(void))rightBlock  andRightTitle:(NSString *)rightTitle{
    
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * actionYes = [UIAlertAction actionWithTitle:rightTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (rightBlock) {
            rightBlock();
        }
    }];
    UIAlertAction *actionNo = [UIAlertAction actionWithTitle:leftTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (leftBlock) {
            leftBlock();
        }
    }];
    [alert addAction:actionNo];
    [alert addAction:actionYes];
    
    [[MYGlobal share].lastVC presentViewController:alert animated:YES completion:nil];
}



+(void)createAlertWithTitle:(NSString *)title andLeftBtnClick:(void (^)(void))leftBlock andRightBtnClick:(void (^)(void))rightBlock  {
    
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * actionYes = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (rightBlock) {
            rightBlock();
        }
    }];
    UIAlertAction *actionNo = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (leftBlock) {
            leftBlock();
        }
    }];
    [alert addAction:actionNo];
    [alert addAction:actionYes];
    
    [[MYGlobal share].lastVC presentViewController:alert animated:YES completion:nil];
}
+(void)createAlertWithTitle:(NSString *)title andBtnClick:(void (^)(void))rightBlock{
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * actionYes = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (rightBlock) {
            rightBlock();
        }
    }];
    [actionYes setValue:MyColor(@"1d1d1d") forKey:@"_titleTextColor"];
    [alert addAction:actionYes];
    
    [[MYGlobal share].lastVC presentViewController:alert animated:YES completion:nil];
}



+ (NSData *)compactFormatDataForDictionary:(NSDictionary *)dicJson{
    
    if (![dicJson isKindOfClass:[NSDictionary class]]) {
        
        return nil;
        
    }
    
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dicJson options:0 error:nil];
    
    if (![jsonData isKindOfClass:[NSData class]]) {
        
        return nil;
        
    }
    
    return jsonData;
    
}


+ (NSDictionary *)dictionaryForJsonData:(NSData *)jsonData

{
    
    if (![jsonData isKindOfClass:[NSData class]] || jsonData.length < 1) {
        
        return nil;
        
    }
    
    id jsonObj = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:nil];
    
    if (![jsonObj isKindOfClass:[NSDictionary class]]) {
        
        return nil;
        
    }
    
    return [NSDictionary dictionaryWithDictionary:(NSDictionary *)jsonObj];
    
}

/*
 行间距(没有行间距就传0)
 @param font        文本字体大小
 
 @return 文本高度
 */
+(CGFloat)getTextHeightWithStr:(NSString *)str
                     withWidth:(CGFloat)width
               withLineSpacing:(CGFloat)lineSpacing
                      withFont:(UIFont *)font
{
    if (!str || str.length == 0) {
        return 0;
    }
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc]init];
    paraStyle.lineSpacing = lineSpacing;
    NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:str
                                                                                       attributes:@{NSParagraphStyleAttributeName:paraStyle,NSFontAttributeName:font}];
    
    CGRect rect = [attributeString boundingRectWithSize:CGSizeMake(width, MAXFLOAT)
                                                options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
                                                context:nil];
    
    if ((rect.size.height - font.lineHeight)  <= lineSpacing){
        if ([Helper containChinese:str]){
            rect.size.height -= lineSpacing;
        }
    }
    return rect.size.height;
}
//判断是否包含中文
+(BOOL)containChinese:(NSString *)str {
    for(int i=0; i< [str length];i++){
        int a = [str characterAtIndex:i];
        if( a > 0x4e00 && a < 0x9fff){
            return YES;
        }
    }
    return NO;
}


+ (NSString *) returnTimeText:(NSString *)time{
    
    NSTimeInterval currentTime = [[NSDate date] timeIntervalSince1970];
    NSTimeInterval createTime;
    // 创建歌曲时间戳(后台返回的时间 一般是13位数字)
    if (time.length >=13) {
        createTime = time.doubleValue/1000;
    }else {
        createTime = time.doubleValue;
    }
    
    // 时间差
    NSTimeInterval tempTime = currentTime - createTime;
    
    if (tempTime < 60) {
        return  [NSString stringWithFormat:@"刚刚"];
    }
    // 秒转小时
    NSInteger mins = tempTime/60;
    if(mins <60){
        return [NSString stringWithFormat:@"%ld分钟前",mins];
    }
    // 秒转小时
    NSInteger hours = tempTime/3600;
    if (hours<24) {
        return [NSString stringWithFormat:@"%ld小时前",hours];
    }
    //秒转天数
    NSInteger days = tempTime/3600/24;
    if (days < 30) {
        return [NSString stringWithFormat:@"%ld天前",days];
    }
    //    if (days <360) {
    //       return [Helper convertTimesInterval:time andDealTimeType:DealTimeType_DayMinutes];
    //    }
    //    return [Helper convertTimesInterval:time andDealTimeType:DealTimeType_Minutes];
    
    
    //秒转月
    NSInteger months = tempTime/3600/24/30;
    if (months < 12) {
        return [NSString stringWithFormat:@"%ld月前",months];
    }
    //秒转年
    NSInteger years = tempTime/3600/24/30/12;
    return [NSString stringWithFormat:@"%ld年前",years];
}

+ (void)setDiferentColors:(NSArray *)colors  WithView:(UIView *)view withFlag:(ColorDirection)direction{
    if([view.layer.sublayers[0] isKindOfClass:[CAGradientLayer class]]){
        CAGradientLayer *gradientLayer = view.layer.sublayers[0];
        gradientLayer.colors = colors;
        return;
    }
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = view.bounds;
    gradientLayer.cornerRadius = view.layer.cornerRadius;
    // 渐变色颜色数组,可多个
    gradientLayer.colors = colors;
    
    //（0，0）为左上角、（1，0）为右上角、（0，1）为左下角、（1，1）为右下角
    if (direction == ColorDirectionLeft) {
        // 渐变的开始点 (不同的起始点可以实现不同位置的渐变,如图)
        gradientLayer.startPoint = CGPointMake(0, 0);
        // 渐变的结束点
        gradientLayer.endPoint = CGPointMake(1, 0);
    }else if(direction == ColorDirectionRight){
        // 渐变的开始点 (不同的起始点可以实现不同位置的渐变,如图)
        gradientLayer.startPoint = CGPointMake(1, 0);
        // 渐变的结束点
        gradientLayer.endPoint = CGPointMake(0, 0);
    }else if(direction == ColorDirectiondown){
        // 渐变的开始点 (不同的起始点可以实现不同位置的渐变,如图)
        gradientLayer.startPoint = CGPointMake(0, 0);
        // 渐变的结束点
        gradientLayer.endPoint = CGPointMake(0, 1);
    }else{
        // 渐变的开始点 (不同的起始点可以实现不同位置的渐变,如图)
        gradientLayer.startPoint = CGPointMake(0, 1);
        // 渐变的结束点
        gradientLayer.endPoint = CGPointMake(0, 0);
    }
    
    [view.layer insertSublayer:gradientLayer atIndex:0];
}

+(void)setLabelInfo:(NSArray *_Nullable)strArray withLabel:(UILabel *_Nullable)label{
    NSMutableString *tempStr = [[NSMutableString alloc]init];
    
    for (NSString *str in strArray[0]) {
        [tempStr appendString:str];
    }
    
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:tempStr];
    
    for (int i = 0 ;i < [strArray[0] count]; i++) {
        NSString *str = strArray[0][i];
        NSString *color = strArray[1][i];
        
        [attStr addAttribute:NSForegroundColorAttributeName value:color range:[tempStr rangeOfString:str]];
        if (strArray.count == 3) {
            NSString *font = strArray[2][i];
            [attStr addAttribute:NSFontAttributeName value:font range:[tempStr rangeOfString:str]];
        }
    }
    label.attributedText = attStr;
}

#pragma 正则匹配手机号
+ (BOOL)checkTelNumber:(NSString *) telNumber
{
    NSString *pattern = @"^1+\\d{10}";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
    BOOL isMatch = [pred evaluateWithObject:telNumber];
    return isMatch;
}


#pragma 正则匹配用户密码6-15位数字和字母组合
+ (BOOL)checkPassword:(NSString *) password
{
    NSString *pattern = @"^(?![0-9]+$)(?![a-zA-Z]+$)[a-zA-Z0-9]{6,15}";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
    BOOL isMatch = [pred evaluateWithObject:password];
    return isMatch;
    
}


+ (NSString *)hidefourNumFromPhone:(NSString *)phone{
    if (phone.length >= 11) {
        return  [phone stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@" **** "];
    }else{
        return phone;
    }
}

+ (NSDate *)timeChangDateWithTimeStr:(NSString *)time witForat:(NSString *)form{
    NSDateFormatter* dateFormat = [[NSDateFormatter alloc]init];//实例化一个NSDateFormatter对象
    [dateFormat setDateFormat:form];//设定时间格式,这里可以设置成自己需要的格式
    NSDate *date =[dateFormat dateFromString:time];
    return date;
}

+ (NSArray *)getTime{
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"HH"];
    NSString *str = [formatter stringFromDate:[NSDate date]];
    int time = [str intValue];
    NSString *tempStr = @"";
    if (time > 5||time <= 9) {
        tempStr = @"早上好";
    }else if (time > 9||time <= 12){
        tempStr = @"中午好";
    }else if (time > 12||time <= 13){
        tempStr = @"中午好";
    }else if (time > 13||time <= 19){
        tempStr = @"下午好";
    }else if (time > 19||time <= 24){
        tempStr = @"晚上好";
    }else if (time > 0||time <= 5){
        tempStr = @"凌晨好";
    }else{
        tempStr = @"好";
    }
    [formatter setDateFormat:@"HH:mm"];
    NSArray *tempArray = [NSArray arrayWithObjects:tempStr,[formatter stringFromDate:[NSDate date]], nil];
    return tempArray;
}


+ (NSString *)getCurrentMonth{
    NSDate *date = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    //获取当前时间日期展示字符串 如：2019-05-23-13:58:59
    NSString *str = [formatter stringFromDate:date];
    
    //下面是单独获取每项的值
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    NSInteger unitFlags = NSCalendarUnitYear |NSCalendarUnitMonth |NSCalendarUnitDay |NSCalendarUnitWeekday |NSCalendarUnitHour |NSCalendarUnitMinute |NSCalendarUnitSecond;
    comps = [calendar components:unitFlags fromDate:date];
    //星期 注意星期是从周日开始计算
    long week = [comps weekday];
    //年
    long year=[comps year];
    //月
    long month = [comps month];
    //日
    long day = [comps day];
    //时
    long hour = [comps hour];
    //分
    long minute = [comps minute];
    //秒
    long second = [comps second];
    
    return [NSString stringWithFormat:@"%ld-%ld",year,month];
}

+ (NSString *)getCurrent0Month{
    NSDate *date = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    //获取当前时间日期展示字符串 如：2019-05-23-13:58:59
    NSString *str = [formatter stringFromDate:date];
    
    //下面是单独获取每项的值
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    NSInteger unitFlags = NSCalendarUnitYear |NSCalendarUnitMonth |NSCalendarUnitDay |NSCalendarUnitWeekday |NSCalendarUnitHour |NSCalendarUnitMinute |NSCalendarUnitSecond;
    comps = [calendar components:unitFlags fromDate:date];
    //星期 注意星期是从周日开始计算
    long week = [comps weekday];
    //年
    long year=[comps year];
    //月
    long month = [comps month];
    //日
    long day = [comps day];
    //时
    long hour = [comps hour];
    //分
    long minute = [comps minute];
    //秒
    long second = [comps second];
    
    if (month < 10) {
        return [NSString stringWithFormat:@"%ld-0%ld",year,month];
    }
    return [NSString stringWithFormat:@"%ld-%ld",year,month];
}

+ (NSString *)judgeNull:(id)object{
    if ([object isKindOfClass:[NSNull class]]) {
        return  @"";
    }else{
        return object;
    }
}

+ (void)showListWithTitle:(NSString *)title withList:(NSArray *)array{
    UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, MY_Screen_W, MY_Screen_H)];
    bgView.backgroundColor = [MYColor colorWithHexString:@"111111" alpha:0.3];
    
    CGFloat hegith = (array.count * 45) + SafeBottomMargin + 60;
    UIView *contentView = [[UIView alloc]initWithFrame:CGRectMake(0, MY_Screen_H - hegith, MY_Screen_W, hegith + 15)];
    contentView.backgroundColor = UIColor.whiteColor;
    contentView.layer.cornerRadius = 15;
    [bgView addSubview:contentView];
    
    UIButton *hideBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    hideBtn.backgroundColor = [UIColor clearColor];
    
    [hideBtn addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        [bgView removeFromSuperview];
    }]];
    hideBtn.frame = CGRectMake(0, 0, MY_Screen_W, MY_Screen_H  - hegith);
    [bgView addSubview:hideBtn];
    [[UIApplication sharedApplication].delegate.window addSubview:bgView];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, MY_Screen_W, 60)];
    label.text = title;
    label.font = MY_SCALE_FONT(17);
    label.textColor = MYBlock;
    label.textAlignment = NSTextAlignmentCenter;
    [contentView addSubview:label];
    
    UIButton *canCelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    canCelBtn.frame = CGRectMake(MY_Screen_W - 40, 0, 40, 60);
    [canCelBtn setImage:[UIImage imageNamed:@"login_cancel"] forState:UIControlStateNormal];
    [contentView addSubview:canCelBtn];
    canCelBtn.centerY = label.centerY;
    [canCelBtn addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithActionBlock:^(id  _Nonnull sender) {
        [bgView removeFromSuperview];
    }]];
    
    UIView *topLine = [[UILabel alloc]initWithFrame:CGRectMake(0, 59, MY_Screen_W, 1)];
    topLine.backgroundColor = MyColor(@"#E6E7F2");
    [contentView addSubview:topLine];
    
    UIView *tempView;
    for (int i = 0; i < array.count; i ++) {
        NSArray *tempArray = array[i];
        UILabel *temLabel = [[UILabel alloc]init];
        temLabel.text = tempArray[0];
        temLabel.font = MY_SCALE_FONT(14);
        temLabel.textColor = MyColor(@"333333");
        [contentView addSubview:temLabel];
        [temLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            if (tempView) {
                make.top.equalTo(tempView.mas_bottom);
            }else{
                make.top.equalTo(topLine.mas_bottom);
            }
            make.height.mas_equalTo(44.5);
        }];
        
        if (tempArray.count == 3) {
            UILabel *detailLabel = [[UILabel alloc]init];
            detailLabel.text = tempArray[2];
            detailLabel.font = MY_SCALE_FONT(14);
            detailLabel.textColor = MyColor(@"333333");
            [contentView addSubview:detailLabel];
            [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(temLabel.mas_right);
                make.centerY.equalTo(temLabel);
            }];
        }
        UILabel *tem1Label = [[UILabel alloc]init];
        tem1Label.text = tempArray[1];
        tem1Label.font = MY_SCALE_FONT(14);
        tem1Label.textColor = MyColor(@"333333");
        [contentView addSubview:tem1Label];
        [tem1Label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(contentView).offset(-15);
            make.centerY.equalTo(temLabel);
        }];
        
        UIView *line = [[UILabel alloc]init];
        line.backgroundColor = MyColor(@"#E6E7F2");
        [contentView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(contentView);
            make.height.mas_equalTo(0.5);
            make.top.mas_equalTo(temLabel.mas_bottom);
        }];
        tempView = line;
        if ([temLabel.text containsString:@"合计"]) {
            temLabel.font = MY_SCALE_BoldFont(15);
            tem1Label.font = MY_SCALE_BoldFont(16);
            tem1Label.textColor = MYRed;
        }
    }
}
+ (void)selectPayTypeView:(void (^_Nullable)(NSString * _Nullable type1))type withCancel:(void (^_Nullable)(NSString * _Nullable info))cancel{
    //    if ([MYGlobal share].wechatFlag == 1) {
    //        [QMUITips showError:@"正在开发，请等待下一次更新"];
    //        return;
    //    }
    UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, MY_Screen_W, MY_Screen_H)];
    bgView.backgroundColor = [MYColor colorWithHexString:@"111111" alpha:0.3];
    
    CGFloat hegith = 65 + 2 * 55 + SafeBottomMargin + 20 ;
    UIView *contentView = [[UIView alloc]initWithFrame:CGRectMake(0, MY_Screen_H, MY_Screen_W, hegith + 15 + 20)];
    contentView.backgroundColor = UIColor.whiteColor;
    contentView.layer.cornerRadius = 15;
    [bgView addSubview:contentView];
    
    UIButton *hideBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    hideBtn.backgroundColor = [UIColor clearColor];
    
    [hideBtn addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        cancel(@"");
        [bgView removeFromSuperview];
    }]];
    hideBtn.frame = CGRectMake(0, 0, MY_Screen_W, MY_Screen_H  - hegith);
    [bgView addSubview:hideBtn];
    [[UIApplication sharedApplication].delegate.window addSubview:bgView];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, MY_Screen_W, 65)];
    label.text = @"选择支付方式";
    label.font = MY_SCALE_FONT(17);
    label.textColor = MYBlock;
    label.textAlignment = NSTextAlignmentCenter;
    [contentView addSubview:label];
    
    UIButton *canCelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    canCelBtn.frame = CGRectMake(MY_Screen_W - 40, 0, 40, 40);
    [canCelBtn setImage:[UIImage imageNamed:@"login_cancel"] forState:UIControlStateNormal];
    [contentView addSubview:canCelBtn];
    canCelBtn.centerY = label.centerY;
    [canCelBtn addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithActionBlock:^(id  _Nonnull sender) {
        cancel(@"");
        [UIView animateWithDuration:0.2 animations:^{
            contentView.top = MY_Screen_H;
        } completion:^(BOOL finished) {
            [bgView removeFromSuperview];
        }];
    }]];
    
    UIView *topLine = [[UILabel alloc]initWithFrame:CGRectMake(0, label.bottom, MY_Screen_W, 0.5)];
    topLine.backgroundColor = MyColor(@"#E6E7F2");
    [contentView addSubview:topLine];
    
    UIView *tempView;
    NSArray *array = @[
        @{@"title":@"微信",@"img":@"createOrder_wechat"},
        @{@"title":@"支付宝",@"img":@"createOrder_alipay"},
    ];
    //order_pay_yes
    for (int i = 0; i < array.count; i ++) {
        UILabel *temLabel = [[UILabel alloc]init];
        temLabel.text = array[i][@"title"];
        temLabel.font = MY_SCALE_FONT(14);
        temLabel.textColor = MyColor(@"444444");
        [contentView addSubview:temLabel];
        [temLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(65);
            if (tempView) {
                make.top.equalTo(tempView.mas_bottom);
            }else{
                make.top.equalTo(topLine.mas_bottom);
            }
            make.height.mas_equalTo(55);
        }];
        
        UIImageView *leftImgView = [[UIImageView alloc]initWithImage: [UIImage imageNamed:array[i][@"img"]]];
        [contentView addSubview:leftImgView];
        [leftImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(temLabel.mas_left).offset(-10);
            make.centerY.equalTo(temLabel);
        }];
        
        UIImageView *selectImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"order_pay_no"]];
        [contentView addSubview:selectImgView];
        [selectImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(contentView).offset(-10);
            make.centerY.equalTo(temLabel);
        }];
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.backgroundColor = UIColor.clearColor;
        [contentView addSubview:btn];
        btn.tag = 1000 + i;
        [btn addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
            type([NSString stringWithFormat:@"%ld",btn.tag - 1000]);
            [UIView animateWithDuration:0.2 animations:^{
                contentView.top = MY_Screen_H;
            } completion:^(BOOL finished) {
                [bgView removeFromSuperview];
            }];
        }]];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(leftImgView);
            make.top.bottom.equalTo(temLabel);
            make.right.equalTo(selectImgView);
        }];
        
        UIView *line = [[UILabel alloc]init];
        line.backgroundColor = MyColor(@"#E6E7F2");
        [contentView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(contentView);
            make.height.mas_equalTo(0.5);
            make.top.mas_equalTo(temLabel.mas_bottom);
        }];
        tempView = line;
    }
    
    [UIView animateWithDuration:0.2 animations:^{
        contentView.top = MY_Screen_H - hegith;
    } completion:^(BOOL finished) {
        
    }];
}

//模型转字典
+ (NSDictionary *)dicFromObject:(NSObject *)object {
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    unsigned int count;
    objc_property_t *propertyList = class_copyPropertyList([object class], &count);
    
    for (int i = 0; i < count; i++) {
        objc_property_t property = propertyList[i];
        const char *cName = property_getName(property);
        NSString *name = [NSString stringWithUTF8String:cName];
        NSObject *value = [object valueForKey:name];//valueForKey返回的数字和字符串都是对象
        
        if ([value isKindOfClass:[NSString class]] || [value isKindOfClass:[NSNumber class]]) {
            //string , bool, int ,NSinteger
            [dic setObject:value forKey:name];
            
        } else if ([value isKindOfClass:[NSArray class]]) {
            //数组或字典
            [dic setObject:[self arrayWithObject:value] forKey:name];
        } else if ([value isKindOfClass:[NSDictionary class]]) {
            //数组或字典
            [dic setObject:[self dicWithObject:value] forKey:name];
        } else if (value == nil) {
            //null
            //[dic setObject:[NSNull null] forKey:name];//这行可以注释掉?????
        } else {
            //model
            [dic setObject:[self dicFromObject:value] forKey:name];
        }
    }
    
    return [dic copy];
}

//转数组
+ (NSArray *)arrayWithObject:(id)object {
    //数组
    NSMutableArray *array = [NSMutableArray array];
    NSArray *originArr = (NSArray *)object;
    if ([originArr isKindOfClass:[NSArray class]]) {
        for (NSObject *object in originArr) {
            if ([object isKindOfClass:[NSString class]]||[object isKindOfClass:[NSNumber class]]) {
                //string , bool, int ,NSinteger
                [array addObject:object];
            } else if ([object isKindOfClass:[NSArray class]]) {
                //数组或字典
                [array addObject:[self arrayWithObject:object]];
            } else if ([object isKindOfClass:[NSDictionary class]]) {
                //数组或字典
                [array addObject:[self dicWithObject:object]];
            } else {
                //model
                [array addObject:[self dicFromObject:object]];
            }
        }
        return [array copy];
    }
    return array.copy;
}

//转字典类型
+ (NSDictionary *)dicWithObject:(id)object {
    //字典
    NSDictionary *originDic = (NSDictionary *)object;
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    if ([object isKindOfClass:[NSDictionary class]]) {
        for (NSString *key in originDic.allKeys) {
            id object = [originDic objectForKey:key];
            if ([object isKindOfClass:[NSString class]]||[object isKindOfClass:[NSNumber class]]) {
                //string , bool, int ,NSinteger
                [dic setObject:object forKey:key];
            } else if ([object isKindOfClass:[NSArray class]]) {
                //数组或字典
                [dic setObject:[self arrayWithObject:object] forKey:key];
            } else if ([object isKindOfClass:[NSDictionary class]]) {
                //数组或字典
                [dic setObject:[self dicWithObject:object] forKey:key];
            } else {
                //model
                [dic setObject:[self dicFromObject:object] forKey:key];
            }
        }
        return [dic copy];
    }
    return dic.copy;
}
//获取城市编码  北京110100
+(NSString *)getCityCodeWithName:(NSString *)cityName{
    NSString *strResourcesBundle = [[NSBundle mainBundle] pathForResource:@"CGXPickerViewBundle" ofType:@"bundle"];
    NSString *filePath = [[NSBundle bundleWithPath:strResourcesBundle] pathForResource:@"CGXAddressCity" ofType:@"plist"];
    NSArray *arrData = [NSArray arrayWithContentsOfFile:filePath];
    NSString *code = @"110100";
    //NSMutableArray *tempArray = [NSMutableArray new];
    for (NSDictionary *dict1 in arrData) {
        NSMutableArray *cityArr = [dict1 objectForKey:@"n"];
        for (NSDictionary *dict2 in cityArr) {
            if (![[dict2 objectForKey:@"v"] isEqualToString:@"不限"]) {
                //NSMutableDictionary *dic3 = [NSMutableDictionary dictionary];
                if ([cityName isEqualToString:[dict2 objectForKey:@"v"]]) {
                    code = [dict2 objectForKey:@"k"];
                }
                //[dic3 setObject:[dict2 objectForKey:@"v"] forKey:@"name"];
                //[dic3 setObject:[dict2 objectForKey:@"k"] forKey:@"code"];
                
                //[tempArray addObject:dic3];
            }
        }
    }
    return code;
}

//邮箱
+ (BOOL) validateEmail:(NSString *_Nullable)email{
    
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    
    return [emailTest evaluateWithObject:email];
    
}

//判断移动
+ (BOOL)isChinaMobile:(NSString *)phoneNum{
    NSString * CM = @"(^1(3[4-9]|4[78]|5[0-27-9]|6[6]|7[8]|8[2-478]|9[8])\\d{8}$)|(^1705\\d{7}$)";
    NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
    return [regextestcm evaluateWithObject:phoneNum];
    
}

//判断联通
+ (BOOL)isChinaUnicom:(NSString *)phoneNum{
    NSString * CM = @"(^1(3[0-2]|4[56]|5[56]|6[6]|7[156]|8[56])\\d{8}$)|(^1704\\d{7}$)|(^1707\\d{7}$)|(^1708\\d{7}$)|(^1709\\d{7}$)";
    NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
    return [regextestcm evaluateWithObject:phoneNum];
}

//判断电信
+ (BOOL)isChinaTelecom:(NSString *)phoneNum{
    NSString * CM = @"(^1(3[3]|4[9]|5[3]|7[347]|8[019]|9[19])\\d{8}$)|(^1700\\d{7}$)|(^1701\\d{7}$)|(^1702\\d{7}$)";
    NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
    return [regextestcm evaluateWithObject:phoneNum];
}

//判断运营商

+ (NSString *)getPhoneNumType:(NSString *)phoneNum{
    return [self isChinaMobile:phoneNum]? @"中国移动": ([self isChinaUnicom:phoneNum]? @"中国联通":([self isChinaTelecom:phoneNum]? @"中国电信": @"未知"));
}

+ (void)alertShowWithTitle:(NSString *)title withContent:(NSString *)content withBtnTitle:(NSString *)btnTitle withCancel:(void (^)(BOOL))cancel{
    UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, MY_Screen_W, MY_Screen_H)];
    bgView.backgroundColor = [MYColor colorWithHexString:@"#010811" alpha:0.6];
    [[UIApplication sharedApplication].delegate.window.rootViewController.view addSubview:bgView];
    UIView *contentView = [[UIView alloc]init];
    contentView.backgroundColor = UIColor.whiteColor;
    contentView.layer.cornerRadius = 10;
    [bgView addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(50);
        make.right.mas_equalTo(-50);
        make.center.equalTo(bgView);
    }];
    
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.text = title;
    titleLabel.font = MY_SCALE_RegularFONT(15);
    titleLabel.textColor = MYBlock;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [contentView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.top.equalTo(contentView);
        make.height.mas_equalTo(46);
    }];
    
    UILabel *contentLabel = [[UILabel alloc]init];
    contentLabel.text = content;
    contentLabel.numberOfLines = 0;
    contentLabel.lineBreakMode = NSLineBreakByWordWrapping;
    contentLabel.textAlignment = NSTextAlignmentCenter;
    contentLabel.font = MY_SCALE_RegularFONT(12);
    contentLabel.textColor = MyColor(@"666666");;
    [contentView addSubview:contentLabel];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLabel.mas_bottom).offset(3);
        make.left.right.equalTo(titleLabel);
    }];
    
    UIView *line = [[UIView alloc]init];
    line.backgroundColor = MyColor(@"#EEEEEE");
    [contentView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(contentView);
        make.height.mas_equalTo(0.5);
        make.top.equalTo(contentLabel.mas_bottom).offset(20);
    }];
    
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [contentView addSubview:btn];
    [btn setTitle:btnTitle forState:UIControlStateNormal];
    [btn setTitleColor:ThemeColor forState:UIControlStateNormal];
    btn.titleLabel.font = MY_SCALE_SemiboldFONT(14);
    [btn addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        cancel(YES);
        [bgView removeFromSuperview];
    }]];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(contentView);
        make.top.equalTo(line.mas_bottom);
        make.height.mas_equalTo(40);
        make.bottom.equalTo(contentView);
    }];
}
+(void)alertShowWithTitle:(NSString *_Nullable)title withContent:(NSString *_Nullable)content withSureBtnTitle:(NSString *_Nullable)btnSureTitle withCancelBtnTitle:(NSString *_Nullable)btnCancelTitle withSelect:(void (^_Nullable)(NSInteger index))selected{
    UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, MY_Screen_W, MY_Screen_H)];
    bgView.backgroundColor = [MYColor colorWithHexString:@"#010811" alpha:0.6];
    [[UIApplication sharedApplication].delegate.window addSubview:bgView];
    UIView *contentView = [[UIView alloc]init];
    contentView.backgroundColor = ciThemeColor;
    contentView.layer.cornerRadius = 10;
    [bgView addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(55);
        make.right.equalTo(bgView.mas_right).offset(-55);
        make.centerY.equalTo(bgView);
    }];
    
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.text = title;
    titleLabel.font = MY_SCALE_SemiboldFONT(16);
    titleLabel.textColor = MYBlock;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [contentView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.equalTo(contentView).offset(-20);
        make.top.mas_equalTo(10);
    }];
    
    UILabel *contentLabel = [[UILabel alloc]init];
    contentLabel.text = content;
    contentLabel.numberOfLines = 0;
    contentLabel.lineBreakMode = NSLineBreakByWordWrapping;
    contentLabel.textAlignment = NSTextAlignmentCenter;
    contentLabel.font = MY_SCALE_RegularFONT(14);
    contentLabel.textColor = MyColor(@"666666");
    [contentView addSubview:contentLabel];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleLabel);
        make.top.equalTo(titleLabel.mas_bottom).offset(10);
    }];
    
    UIView *line = [[UIView alloc]init];
    line.backgroundColor = MyColor(@"eeeeee");
    [contentView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(contentView);
        make.top.equalTo(contentLabel.mas_bottom).offset(20);
        make.height.mas_equalTo(0.5);
        make.bottom.equalTo(contentView).offset(-44);
    }];
    
    
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [contentView addSubview:cancelBtn];
    [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.equalTo(contentView);
        make.height.mas_equalTo(44);
        make.width.mas_equalTo((MY_Screen_W - 110 ) / 2);
    }];
    [cancelBtn setTitle:btnCancelTitle forState:UIControlStateNormal];
    [cancelBtn setTitleColor:MyColor(@"666666") forState:UIControlStateNormal];
    cancelBtn.titleLabel.font = MY_SCALE_RegularFONT(14);
    [cancelBtn addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        selected(0);
        [bgView removeFromSuperview];
    }]];
    
    UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [contentView addSubview:sureBtn];
    [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(cancelBtn.mas_right);
        make.height.bottom.width.equalTo(cancelBtn);
    }];
    [sureBtn setTitle:btnSureTitle forState:UIControlStateNormal];
    [sureBtn setTitleColor:MYBlue forState:UIControlStateNormal];
    sureBtn.titleLabel.font = MY_SCALE_SemiboldFONT(14);
    [sureBtn addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        selected(1);
        [bgView removeFromSuperview];
    }]];
    
    UIView *shuLine = [[UIView alloc]init];
    shuLine.backgroundColor = MyColor(@"eeeeee");
    [contentView addSubview:shuLine];
    [shuLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.height.equalTo(sureBtn);
        make.width.mas_equalTo(0.5);
    }];
}

+ (void)alertShowWithTitle:(NSString *)title withSureBtnTitle:(NSString *)btnSureTitle withCancelBtnTitle:(NSString *)btnCancelTitle withAnwer:(void (^)(NSString * _Nullable anwer))anwerBlock{
    UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, MY_Screen_W, MY_Screen_H)];
    bgView.backgroundColor = [MYColor colorWithHexString:@"#010811" alpha:0.6];
    [[UIApplication sharedApplication].delegate.window addSubview:bgView];
    UIView *contentView = [[UIView alloc]init];
    contentView.backgroundColor = ciThemeColor;
    contentView.layer.cornerRadius = 10;
    [bgView addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(55);
        make.right.equalTo(bgView.mas_right).offset(-55);
        make.centerY.equalTo(bgView);
    }];
    
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.text = title;
    titleLabel.font = MY_SCALE_RegularFONT(15);
    titleLabel.textColor = UIColor.whiteColor;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [contentView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.equalTo(contentView).offset(-20);
        make.top.mas_equalTo(10);
    }];
    
    QMUITextField *rpwField = [[QMUITextField alloc]init];
    rpwField.placeholder = @"请输入";
    rpwField.backgroundColor = MyColor(@"#3A3D42");
    rpwField.placeholderColor = MyColor(@"999999");
    rpwField.textAlignment = NSTextAlignmentCenter;
    rpwField.layer.cornerRadius = 5;
    rpwField.textColor = UIColor.whiteColor;
    rpwField.font = MY_SCALE_RegularFONT(14);
    [contentView addSubview:rpwField];
    [rpwField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(17);
        make.right.equalTo(contentView).offset(-17);
        make.top.equalTo(titleLabel.mas_bottom).offset(17);
        make.height.mas_equalTo(40);
    }];
    
    UIView *line = [[UIView alloc]init];
    line.backgroundColor = MyColor(@"#303339");
    [contentView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(contentView);
        make.top.equalTo(rpwField.mas_bottom).offset(20);
        make.height.mas_equalTo(0.5);
        make.bottom.equalTo(contentView).offset(-44);
    }];
    
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [contentView addSubview:cancelBtn];
    [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.equalTo(contentView);
        make.height.mas_equalTo(44);
        make.width.mas_equalTo((MY_Screen_W - 110 ) / 2);
    }];
    [cancelBtn setTitle:btnCancelTitle forState:UIControlStateNormal];
    [cancelBtn setTitleColor:MyColor(@"999999") forState:UIControlStateNormal];
    cancelBtn.titleLabel.font = MY_SCALE_RegularFONT(14);
    [cancelBtn addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        anwerBlock(@"");
        [bgView removeFromSuperview];
    }]];
    
    UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [contentView addSubview:sureBtn];
    [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(cancelBtn.mas_right);
        make.height.bottom.width.equalTo(cancelBtn);
    }];
    [sureBtn setTitle:btnSureTitle forState:UIControlStateNormal];
    [sureBtn setTitleColor:MYRed forState:UIControlStateNormal];
    sureBtn.titleLabel.font = MY_SCALE_SemiboldFONT(14);
    [sureBtn addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        anwerBlock(rpwField.text.qmui_trimAllWhiteSpace);
        [bgView removeFromSuperview];
    }]];
    
    UIView *shuLine = [[UIView alloc]init];
    shuLine.backgroundColor = MyColor(@"#303339");
    [contentView addSubview:shuLine];
    [shuLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.height.equalTo(sureBtn);
        make.width.mas_equalTo(0.5);
    }];
}

+ (void)alertSelectWithArray:(NSArray *)array withFinish:(void (^)(NSInteger index,NSString * _Nullable title))finish{
    __block NSInteger selectIndex  = 0;
    UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, MY_Screen_W, MY_Screen_H)];
    bgView.backgroundColor = [MYColor colorWithHexString:@"#010811" alpha:0.6];
    [[UIApplication sharedApplication].delegate.window addSubview:bgView];
    UIView *contentView = [[UIView alloc]initWithFrame:CGRectMake(0, MY_Screen_H, MY_Screen_W, array.count * 50 + 10 + SafeBottomMargin + 50 + 15)];
    contentView.backgroundColor = ciThemeColor;
    contentView.layer.cornerRadius = 15;
    [bgView addSubview:contentView];
    
    NSMutableArray *btns = [NSMutableArray new];
    for (int i = 0; i < array.count; i++) {
        NSString *str = array[i];
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(0, i * 50, MY_Screen_W, 50);
        btn.tag = 1000 + i;
        [btn setTitle:str forState:UIControlStateNormal];
        [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        btn.titleLabel.font = MY_SCALE_RegularFONT(14);
        btn.backgroundColor = UIColor.clearColor;
        [contentView addSubview:btn];
        [btns addObject:btn];
        [btn addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
            UIButton *currBtn = (UIButton *)((UITapGestureRecognizer *)sender).view;
            selectIndex = currBtn.tag - 1000;
            finish(selectIndex,str);
            [UIView animateWithDuration:0.3 animations:^{
                contentView.top = MY_Screen_H;
            } completion:^(BOOL finished) {
                [bgView removeFromSuperview];
            }];
        }]];
    }
    
    UIView *block = [[UIView alloc]initWithFrame:CGRectMake(0, array.count * 50, MY_Screen_W, 10)];
    block.backgroundColor = UIColor.whiteColor;
    [contentView addSubview:block];
    
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelBtn.backgroundColor = [UIColor clearColor];
    [cancelBtn setTitle:LocalizedString(@"取消") forState:UIControlStateNormal];
    [cancelBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    cancelBtn.titleLabel.font = MY_SCALE_RegularFONT(14);
    [cancelBtn addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        finish(-1,@"取消");
        [UIView animateWithDuration:0.3 animations:^{
            contentView.top = MY_Screen_H;
        } completion:^(BOOL finished) {
            [bgView removeFromSuperview];
        }];
    }]];
    cancelBtn.frame = CGRectMake(0, block.bottom, MY_Screen_W, SafeBottomMargin + 50);
    [contentView addSubview:cancelBtn];
    
    
    UIButton *hideBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    hideBtn.backgroundColor = [UIColor clearColor];
    
    [hideBtn addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        [UIView animateWithDuration:0.3 animations:^{
            contentView.top = MY_Screen_H;
        } completion:^(BOOL finished) {
            [bgView removeFromSuperview];
        }];
        
    }]];
    hideBtn.frame = CGRectMake(0, 0, MY_Screen_W, MY_Screen_H  - contentView.height);
    [bgView addSubview:hideBtn];
    
    [UIView animateWithDuration:0.3 animations:^{
        contentView.top = MY_Screen_H - contentView.height + 15;
    }];
}

+ (void)alertShowVipWithTitle:(NSString *)title withContent:(NSString *)content{
    UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, MY_Screen_W, MY_Screen_H)];
    bgView.backgroundColor = [MYColor colorWithHexString:@"#010811" alpha:0.6];
    [[UIApplication sharedApplication].delegate.window addSubview:bgView];
    UIView *contentView = [[UIView alloc]init];
    contentView.backgroundColor = MyColor(@"#FFF0B5");
    contentView.layer.cornerRadius = 15;
    [bgView addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(318);
        make.height.mas_equalTo(300);
        make.center.equalTo(bgView);
    }];
    
    UIImageView *bgImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"t_edit_vip"]];
    [contentView addSubview:bgImgView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(contentView);
    }];
    
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.text = title;
    titleLabel.font = MY_SCALE_SemiboldFONT(17);
    titleLabel.textColor = MyColor(@"#333333");
    titleLabel.text = LocalizedString(@"加入VIP会员");
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [contentView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(119);
        make.centerX.equalTo(bgImgView);
    }];
    
    UILabel *contentLabel = [[UILabel alloc]init];
    contentLabel.text = content;
    contentLabel.font = MY_SCALE_RegularFONT(14);
    contentLabel.textColor = MyColor(@"#666666");
    contentLabel.numberOfLines = 0;
    contentLabel.text = LocalizedString(@"加入VIP，无限使用VIP模板，还有更多福利等着你！");
    contentLabel.lineBreakMode = NSLineBreakByWordWrapping;
    contentLabel.textAlignment = NSTextAlignmentCenter;
    [contentView addSubview:contentLabel];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(35);
        make.top.equalTo(titleLabel.mas_bottom).offset(10);
        make.right.equalTo(contentView).offset(-35);
    }];
    
    
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [cancelBtn setImage:[UIImage imageNamed:@"t_edit_ vip_cancel"] forState:UIControlStateNormal];
    [bgView addSubview:cancelBtn];
    [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(contentView);
        make.width.height.mas_equalTo(25);
        make.top.equalTo(contentView.mas_bottom).offset(30);
    }];
    
    [cancelBtn addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        [bgView removeFromSuperview];
    }]];
    
}

+ (void)privacyAgreementShow{
    UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, MY_Screen_W, MY_Screen_H)];
    bgView.backgroundColor = [MYColor colorWithHexString:@"#000000" alpha:0.5];
    [[UIApplication sharedApplication].delegate.window addSubview:bgView];
    UIView *contentView = [[UIView alloc]init];
    contentView.backgroundColor = UIColor.whiteColor;
    contentView.layer.cornerRadius = 15;
    [bgView addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(30);
        make.center.equalTo(bgView);
        make.width.mas_equalTo(315);
        //make.height.mas_equalTo(455);
    }];
    
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.text = LocalizedString(@"用户协议及隐私政策");
    titleLabel.font = MY_SCALE_SemiboldFONT(15);
    titleLabel.textColor = MyColor(@"333333");
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.numberOfLines = 2;
    [contentView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(contentView).offset(30);
        make.right.equalTo(contentView).offset(-30);
        make.top.mas_equalTo(21);
    }];
    
    YYLabel *contentLabel = [[YYLabel alloc]init];
    contentLabel.numberOfLines = 0;
    contentLabel.preferredMaxLayoutWidth = MY_Screen_W - 100;
    contentLabel.lineBreakMode = NSLineBreakByWordWrapping;
    [contentView addSubview:contentLabel];
    NSMutableString *string = [[NSMutableString alloc]initWithString:LocalizedString(@"    感谢您对本产品的支持，在此将向您告知产品使用过程中，产品可以提供的各项服务以及可能收集的信息和数据，以确保您的权益得到充分地保障。 \n\n我们承诺：\n\n1.我们会严格按照相关法律等保护您的个人信息。 2.如果未经您的授权，我们不会使用您的个人信息用于您未授权的其他途径或目的。\n\n在使用本产品之前，请您阅读本产品相关的")];
    [string appendString:@"《"];
    [string appendString:LocalizedString(@"用户协议")];
    [string appendString:@"》"];
    [string appendString:@"和"];
    [string appendString:@"《"];
    [string appendString:LocalizedString(@"隐私政策")];
    [string appendString:@"》"];
    [string appendString:LocalizedString(@"点击\"同意\"表示您已经完全清楚并接受各条款。")];
    NSRange detailrange = [string rangeOfString:@"1.我们会严格按照相关法律等保护您的个人信息。 2.如果未经您的授权，我们不会使用您的个人信息用于您未授权的其他途径或目的。"];
    NSRange yhrange = [string rangeOfString:LocalizedString(@"用户协议")];
    NSRange xyrange = [string rangeOfString:LocalizedString(@"隐私政策")];
    
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:string];
    attri.yy_font = MY_SCALE_RegularFONT(12);
    attri.yy_color = MyColor(@"333333");
    [attri yy_setFont:MY_SCALE_RegularFONT(13) range:NSMakeRange(0, 80)];
    [attri yy_setColor:MyColor(@"999999") range:detailrange];
    [attri yy_setTextHighlightRange:NSMakeRange(yhrange.location-1, yhrange.length+2) color:MYBlue backgroundColor:UIColor.clearColor tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        [bgView removeFromSuperview];
        WebViewController *controller = [[WebViewController alloc] initWithtitle:LocalizedString(@"用户协议") WithUrl:@"https://docs.qq.com/doc/DRlRsT2NLUnFieVZr"];
        [[MYGlobal share].lastVC.navigationController pushViewController:controller animated:YES];
    }];
    
    [attri yy_setTextHighlightRange:NSMakeRange(xyrange.location-1, xyrange.length+2) color:MYBlue backgroundColor:UIColor.clearColor tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        [bgView removeFromSuperview];
        WebViewController *controller = [[WebViewController alloc] initWithtitle:LocalizedString(@"隐私政策") WithUrl:@"https://docs.qq.com/doc/DRkRFVHRBU3NRQlNm"];
        [[MYGlobal share].lastVC.navigationController pushViewController:controller animated:YES];
    }];
    contentLabel.attributedText = attri;
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLabel.mas_bottom).offset(20);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.bottom.equalTo(contentView).offset(-108);
    }];
    
    UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    sureBtn.layer.cornerRadius = 18;
    sureBtn.backgroundColor = MYBlue;
    [contentView addSubview:sureBtn];
    [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(28);
        make.top.equalTo(contentLabel.mas_bottom).offset(15);
        make.right.equalTo(contentView).offset(-28);
        make.height.mas_equalTo(36);
    }];
    [sureBtn setTitle:LocalizedString(@"同意") forState:UIControlStateNormal];
    [sureBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    sureBtn.titleLabel.font = MY_SCALE_SemiboldFONT(14);
    [sureBtn addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        [bgView removeFromSuperview];
        [[NSUserDefaults standardUserDefaults] setValue:@"privacy" forKey:@"privacy1"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }]];
    
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [contentView addSubview:cancelBtn];
    [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(28);
        make.top.equalTo(sureBtn.mas_bottom).offset(3);
        make.right.equalTo(contentView).offset(-28);
        make.height.mas_equalTo(55);
    }];
    [cancelBtn setTitle:LocalizedString(@"不同意并退出APP >>") forState:UIControlStateNormal];
    [cancelBtn setTitleColor:MyColor(@"cccccc") forState:UIControlStateNormal];
    cancelBtn.titleLabel.font = MY_SCALE_RegularFONT(11);
    [cancelBtn addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        exit(0);
    }]];
}

+ (void)showCheckToStore{
    UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, MY_Screen_W, MY_Screen_H)];
    bgView.backgroundColor = [MYColor colorWithHexString:@"#000000" alpha:0.5];
    [[UIApplication sharedApplication].delegate.window addSubview:bgView];
    UIView *contentView = [[UIView alloc]init];
    contentView.backgroundColor = ciThemeColor;
    contentView.layer.cornerRadius = 15;
    [bgView addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30);
        make.top.mas_equalTo(NAVIH);
        make.bottom.mas_equalTo(MY_Screen_H - 2 * NAVIH);
        make.right.mas_equalTo(-30);
    }];
    
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.text = @"用户协议及隐私政策";
    titleLabel.font = MY_SCALE_SemiboldFONT(15);
    titleLabel.textColor = UIColor.whiteColor;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [contentView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(contentView);
        make.top.mas_equalTo(21);
    }];
    
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [contentView addSubview:cancelBtn];
    [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.bottom.mas_equalTo(-15);
        make.right.equalTo(contentView.mas_centerX).offset(-8);
        make.height.mas_equalTo(50);
    }];
    [cancelBtn setTitle:@"等等再说" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:MYRed forState:UIControlStateNormal];
    cancelBtn.layer.cornerRadius = 25;
    cancelBtn.titleLabel.font = MY_SCALE_RegularFONT(11);
    [cancelBtn addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        exit(0);
    }]];
    
    UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    sureBtn.layer.cornerRadius = 25;
    sureBtn.backgroundColor = MYRed;
    [contentView addSubview:sureBtn];
    [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.bottom.mas_equalTo(-15);
        make.left.equalTo(contentView.mas_centerX).offset(8);
        make.height.mas_equalTo(50);
    }];
    [sureBtn setTitle:@"账号迁移" forState:UIControlStateNormal];
    [sureBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    sureBtn.titleLabel.font = MY_SCALE_SemiboldFONT(14);
    [sureBtn addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/shan-shan-pen-di-fu-nu-jian/appid?mt=8"] options:@{} completionHandler:^(BOOL success) {
            
        }];
    }]];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(30, 50, 300, 50)];

    NSAttributedString *attrStr = [[NSAttributedString alloc] initWithData:[@"" dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil];
    label.attributedText = attrStr;
    [contentView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.bottom.equalTo(cancelBtn.mas_top).offset(-20);
    }];
}

+ (NSString *)getRandStr:(int)num{
    char data[num];
    for (int x=0;x < num;data[x++] = (char)('A' + (arc4random_uniform(26))));
    NSString *randomStr = [[NSString alloc] initWithBytes:data length:num encoding:NSUTF8StringEncoding];
    NSString *string = [NSString stringWithFormat:@"%@",randomStr];
    DLog(@"获取随机字符串 %@",string);
    return string;
}

+ (BOOL)validateWithStartTime:(NSString *)startTime withExpireTime:(NSString *)expireTime {
    NSDate *today = [NSDate date];
    
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    // 时间格式,此处遇到过坑,建议时间HH大写,手机24小时进制和12小时禁止都可以完美格式化
    [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    NSDate *start = [dateFormat dateFromString:startTime];
    NSDate *expire = [dateFormat dateFromString:expireTime];
    
    if ([today compare:start] == NSOrderedDescending && [today compare:expire] == NSOrderedAscending) {
        return YES;
    }
    return NO;
}

+ (NSString *)getOnlyStr {
    NSString *onlyStr = [DWKeychainTool getItemForKey:@"onlyStr"];
    if (onlyStr == nil) {
        NSString *time =  [Helper getCurrentTimes:@"YYYYMMddHHmmss"];
        //获取6位随机数
        NSString *randStr = [Helper getRandStr:6];
        onlyStr = [NSString stringWithFormat:@"%@%@",time,randStr].md5String;
        [DWKeychainTool saveItem:onlyStr key:@"onlyStr"];
    }
    return onlyStr;
}

+ (NSString *)addEncode:(NSString *)str{
    return [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
}

+ (NSString *)removeEncode:(NSString *)str{
    return [str stringByRemovingPercentEncoding];
}


+(void)getImgPath:(UIImage *_Nullable)image finshBlock:(void(^_Nullable)(int result,NSString * _Nullable path))completionBlock{
    //根目录
    NSString *rootPath = NSTemporaryDirectory();
    
    //目录
    NSString *documentPath = [rootPath stringByAppendingPathComponent:@"img"];
    
    //创建目录和文件
    [Helper createDir:documentPath];
    [Helper createFile:documentPath];
    
    //新文件路径+名称
    NSString *newName = [NSString stringWithFormat:@"%@.jpeg",[Helper getCurrentTimes:@"YYYYMMddHHmmss"]];
    NSString *newPath = [Helper removeEncode:[documentPath stringByAppendingPathComponent:newName]];
    DLog(@"newPath==%@",newPath);
    if ([Helper isExistsAtPath:newPath]) {
        newName = [NSString stringWithFormat:@"%@.jpeg",[Helper getCurrentTimes:@"YYYYMMddHHmmss"]];
        newPath = [Helper removeEncode:[documentPath stringByAppendingPathComponent:newName]];
        DLog( @"文件已存在，名称变更：%@",newPath);
    }
    BOOL result = [UIImagePNGRepresentation(image) writeToFile:newPath  atomically:YES];
    if(result){
        completionBlock(0,newPath);
    }else{
        completionBlock(1,@"");
    }
}

#pragma mark - 判断文件(夹)是否存在
+ (BOOL)isExistsAtPath:(NSString *)path {
    return [[NSFileManager defaultManager] fileExistsAtPath:path];
}
+(void)createDir:(NSString *)path{
    NSFileManager *fm=[NSFileManager defaultManager];
    // 创建目录
    DLog(@"path===%@",path);
    if (![fm fileExistsAtPath:path]) {
        BOOL res=[fm createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
        if (res) {
            DLog(@"文件路径创建成功");
        }else{
            DLog(@"文件路径创建失败");
        }
    }else{
        DLog(@"文件路径存在");
    }
}

+(void)createFile:(NSString *)path{
    NSFileManager *fm=[NSFileManager defaultManager];
    path = [path stringByAppendingPathComponent:@"data.json"];
    if (![fm fileExistsAtPath:path]) {
        BOOL res = [fm createFileAtPath:path contents:nil attributes:nil];
        if (res) {
            DLog(@"创建文件成功=%@",path);
        }else{
            DLog(@"创建文件失败");
        }
    }else{
        DLog(@"文件存在");
    }
}
+(void)mergeAndExportVideos:(NSArray*)videosPathArray WithCompletionHandler:(void (^)(NSURL* outPutURL, int code))handler{
    if (videosPathArray.count == 0) {
        return;
    }
    AVMutableComposition *mixComposition = [[AVMutableComposition alloc] init];
    
    AVMutableCompositionTrack *audioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio
                                                                        preferredTrackID:kCMPersistentTrackID_Invalid];
    AVMutableCompositionTrack *videoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo
                                                                        preferredTrackID:kCMPersistentTrackID_Invalid];
    CMTime totalDuration = kCMTimeZero;
    for (int i = 0; i < videosPathArray.count; i++) {
        NSDictionary *opts = [NSDictionary dictionaryWithObject:@(YES) forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
        AVAsset *asset = [AVURLAsset URLAssetWithURL:videosPathArray[i] options:opts];
        NSError *erroraudio = nil;
        　　　　　//获取AVAsset中的音频 或者视频
        AVAssetTrack *assetAudioTrack = [[asset tracksWithMediaType:AVMediaTypeAudio] firstObject];
        　　　　　//向通道内加入音频或者视频
        BOOL ba = [audioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset.duration)
                                      ofTrack:assetAudioTrack
                                       atTime:totalDuration
                                        error:&erroraudio];
        
        NSLog(@"erroraudio:%@%d",erroraudio,ba);
        NSError *errorVideo = nil;
        AVAssetTrack *assetVideoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo]firstObject];
        BOOL bl = [videoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset.duration)
                                      ofTrack:assetVideoTrack
                                       atTime:totalDuration
                                        error:&errorVideo];
        
        NSLog(@"errorVideo:%@%d",errorVideo,bl);
        totalDuration = CMTimeAdd(totalDuration, asset.duration);
    }
    NSLog(@"%@",NSHomeDirectory());
    NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd-HH:mm:ss"];
    NSString *outpath = [
        NSString stringWithFormat:@"%@%@.mov",NSTemporaryDirectory(),[formatter stringFromDate:[NSDate date]]];
    NSURL *mergeFileURL = [NSURL fileURLWithPath:outpath];
    AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition
                                                                      presetName:AVAssetExportPreset640x480];
    exporter.outputURL = mergeFileURL;
    exporter.outputFileType = AVFileTypeMPEG4;
    exporter.shouldOptimizeForNetworkUse = YES;
    [exporter exportAsynchronouslyWithCompletionHandler:^{
        NSLog(@"exporter%@",exporter.error);
        handler(mergeFileURL,(int)exporter.error.code);
    }];
}

+(void)getWANIP{
    NSArray *searchArray = NO ?
        @[ /*IOS_VPN @"/" IP_ADDR_IPv4, IOS_VPN @"/" IP_ADDR_IPv6,*/ IOS_CELLULAR @"/" IP_ADDR_IPv4, IOS_WIFI2 @"/" IP_ADDR_IPv4, IOS_WIFI1 @"/" IP_ADDR_IPv4, IOS_WIFI @"/" IP_ADDR_IPv4 ] :
        @[ /*IOS_VPN @"/" IP_ADDR_IPv6, IOS_VPN @"/" IP_ADDR_IPv4,*/ IOS_CELLULAR @"/" IP_ADDR_IPv6,IOS_WIFI2 @"/" IP_ADDR_IPv6, IOS_WIFI1 @"/" IP_ADDR_IPv6, IOS_WIFI @"/" IP_ADDR_IPv6 ] ;
        
        NSDictionary *addresses = [Helper getIPAddresses];
        NSLog(@"addresses: %@", addresses);
        
        __block NSString *address;
        [searchArray enumerateObjectsUsingBlock:^(NSString *key, NSUInteger idx, BOOL *stop)
         {
             address = addresses[key];
             if(address) *stop = YES;
         } ];
    NSString *ip = [addresses count] ? address : nil;
    if (ip == nil || ip.length < 3){
        [MYGlobal share].gwIP = @"";
    }else{
        [MYGlobal share].gwIP = ip;
    }
    DLog(@"11111111==%@",ip);
}

//获取所有相关IP信息
+ (NSDictionary *)getIPAddresses
{
    NSMutableDictionary *addresses = [NSMutableDictionary dictionaryWithCapacity:8];
    
    // retrieve the current interfaces - returns 0 on success
    struct ifaddrs *interfaces;
    if(!getifaddrs(&interfaces)) {
        // Loop through linked list of interfaces
        struct ifaddrs *interface;
        for(interface=interfaces; interface; interface=interface->ifa_next) {
            if(!(interface->ifa_flags & IFF_UP) /* || (interface->ifa_flags & IFF_LOOPBACK) */ ) {
                continue; // deeply nested code harder to read
            }
            const struct sockaddr_in *addr = (const struct sockaddr_in*)interface->ifa_addr;
            char addrBuf[ MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN) ];
            if(addr && (addr->sin_family==AF_INET || addr->sin_family==AF_INET6)) {
                NSString *name = [NSString stringWithUTF8String:interface->ifa_name];
                NSString *type;
                if(addr->sin_family == AF_INET) {
                    if(inet_ntop(AF_INET, &addr->sin_addr, addrBuf, INET_ADDRSTRLEN)) {
                        type = IP_ADDR_IPv4;
                    }
                } else {
                    const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6*)interface->ifa_addr;
                    if(inet_ntop(AF_INET6, &addr6->sin6_addr, addrBuf, INET6_ADDRSTRLEN)) {
                        type = IP_ADDR_IPv6;
                    }
                }
                if(type) {
                    NSString *key = [NSString stringWithFormat:@"%@/%@", name, type];
                    addresses[key] = [NSString stringWithUTF8String:addrBuf];
                }
            }
        }
        // Free memory
        freeifaddrs(interfaces);
    }
    return [addresses count] ? addresses : nil;
}

@end
